/*裁剪产量统计*/
import React from "react";
import Relay from 'react-relay';
import { message } from 'antd';
import HeaderList from '../components/headerList.js';
import Table from '../components/table.js'
import FindProWorkShopMutation from '../mutation/FindProWorkShop';

import '../css/style.css';

export default class Cut extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            workShopId: null,
            proWorkShopList:[],
            tableDataList:[],
            isTable: false
        }
        this.enterpriseId = sessionStorage.getItem('enterpriseId');
    }
    componentWillMount() {
        this.getworkList()
    }
    getworkList() {
        Relay.Store.commitUpdate(
            new FindProWorkShopMutation({
                enterpriseId:this.enterpriseId,
            }),
            {
                onFailure: () => {
                    message.error('网络请求失败');
                },
                onSuccess: (response) => {
                    let data = response.findProWorkShop.findProWorkShop;
                    if(data.errorCode=='0'){
                        this.setState({
                            proWorkShopList: data.proWorkShopList,
                            workShopId: data.proWorkShopList[0].workShopId,
                        },()=>{

                            this.refs.table.getTableData(data.proWorkShopList[0].workShopId,'2')
                        })
                        this.refs.headerList.setState({
                            proWorkShopList: data.proWorkShopList
                        })

                    } else {
                        message.error(data.value);
                    }
                }
            }
        )
    }

    //车间点击
    workGroupClick(workShopId) {
        this.refs.table.getTableData(workShopId,'2')
    }
    render() {
        return(
            <div className="statistics_box">
                <HeaderList
                    ref={'headerList'}
                    workGroupClick={this.workGroupClick.bind(this)}
                    statisticsType="cut"
                />
                <Table ref={'table'} loading={this.state.loading}/>


                {/*//1裁剪 2缝制 3后整 4包装*/}
            </div>
        )
    }
}